package de.bazinga.rotw.gameModes;

import java.util.Vector;

import com.captiveimagination.jgn.clientserver.JGNClient;
import com.captiveimagination.jgn.clientserver.JGNServer;
import com.jmex.game.state.GameStateManager;

import de.bazinga.rotw.game.RotwGameState;
import de.bazinga.rotw.statistics.OnlineStatistics;
import de.bazinga.rotw.treasure.Treasure;
import de.bazinga.rotw.treasure.TreasureUpdateMessage;

public class TreasureHunt implements GameMode{
	/**
	 * The Treasures for the Mode "TreasureHunt"
	 */
	private Vector<Treasure> treasureList = new Vector<Treasure>();
	
	
	/**
	 * The amount of treasures
	 */
	private int treasureCount = 0;
	
	
	@Override
	public void gameUpdate() {}

	@Override
	public void initClient(JGNClient client) {
		TreasureUpdateMessage tum = new TreasureUpdateMessage();
    	tum.setRequestUpdate(true);
    	client.sendToServer(tum);
	}

	@Override
	public void initServer(JGNServer server) {}

	@Override
	public void playerUpdate() {}

	
	@Override
	public void playerAction() {
		RotwGameState gameState = (RotwGameState)GameStateManager.getInstance().getChild("gameState");
		
		Vector<Treasure> treasureList = getTreasureList();
		for(Treasure t:treasureList) {
			if(t != null && gameState.getPlayer().hasCollision(t, false)) {
				t.found(gameState.getPlayer(),true);
			}
		}
	}

	@Override
	public void reset() {
		OnlineStatistics.treasureHuntStart = System.currentTimeMillis();
	}

	@Override
	public boolean useTeams() {
		return false;
	}
	
	





	public void setTreasureList(Vector<Treasure> treasureList) {
		this.treasureList = treasureList;
		this.treasureCount = treasureList.size();
	}




	public Vector<Treasure> getTreasureList() {
		return treasureList;
	}
	
	
	public int getTreasuresCount() {
		return treasureCount;
	}
	
	public void setTreasureCount(int c) {
		this.treasureCount = c;
	}

}